<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="stylesheets/public.css">
    <link rel="stylesheet" href="stylesheets/bootstrap.min.css">
    <script src="javascripts/jquery-1.7.1.min.js"></script>
    <script src="javascripts/bootstrap.min.js"></script>

    <script>

        $(function(){
            $('.add_online').click(function(){
                $('.createAppForm').eq(0)[0].reset();
                $("input[name=isonline]").val(1);
                $('.create_s').show();
            });


        });

        function saveServer(){
            var appname = $("input[name=appname]").val();
            var version = $("input[name=version]").val();
            var status = $("input[name=status]").val();

            if(appname!=""&&version!=""&&status!=""){
                $('.createAppForm').submit();
            }else{
                alert('有未填的选项');
                return false;
            }
        }

        function getAlltd(td){
            var tdArray = new Array();
            var tdval = $(td).prevAll('td');

            tdval.each(function( i,val){
                var td = ($(val).html());
                tdArray.push(td);
            });

            $('.createServerForm').attr('action','/editAppInfo');
            $("input[name=id]").val(tdArray[3]);
            $("input[name=appname]").val(tdArray[2]);
            $("input[name=version]").val(tdArray[1]);
            $("input[name=status]").val(tdArray[0]);
            $('.create_s').show();
        }


    </script>

</head>
<body>
<div class="main pagecenter round">
    <div class="page-header">
        <h1 class="h1">服务器中的应用</h1>
    </div>
        <table class="table table-hover">
            <thead>
            <tr>
                <th>编号</th>
                <th>应用名称</th>
                <th>版本</th>
                <th>状态</th>
                <th></th>
                <th></th>
                <th></th>
                <th><button class="add_online">增加</button></th>
            </tr>
            </thead>
            <tbody>
            <%
            var data =JSON.parse(appdata);
            if(data!=null){
            data.forEach(function(val,index){
            %>

            <tr>
                <td><%=index + 1%></td>
                <td style="display: none"><%=val.id%></td>
                <td><%=val.app_name%></td>
                <td><%=val.version%></td>
                <td><%=val.status%></td>
                <td class='edittd' onclick='getAlltd(this);'>编辑</td>
                <td><a href="/deleteApp?id=<%=val.id%>">删除</a></td>
            </tr>
            <% });}%>
            </tbody>
        </table>
    <form class="createAppForm" action="/createAppInfo" method="post">
        <table class="create_s" style="display: none">
            <tr>
                <td><input class="online_input" type="hidden" name="id" value=""></td>
                <td><input class="online_input" type="text" name="appname" value="" placeholder="应用名称"></td>
                <td><input class="online_input" type="text" name="version" value="" placeholder="版本"></td>
                <td><input class="online_input" type="text" name="status" value="" placeholder="状态"></td>
                <td><a href="javascript:void(0)" class="online_btn" onclick="saveServer();">保存</a>
            </tr>
        </table>
    </form>
</div>

</body>
</html>